<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="3" :lg="7" :md="8" :sm="24">
            <edu-button type="3" @click="filter" icon="filter" title="筛选"></edu-button>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item title="选择班级" :labelCol="labelCol" :wrapperCol="wrapperCol">
<!--              <a-input-search ref="class" v-model="queryParam.jxbid" readOnly unselectable="on" @search="onSearchClass">-->
<!--                <a-button slot="enterButton" :disabled="disabled">选择班级</a-button>-->
<!--              </a-input-search>-->
                  <j-select-banji v-model="queryParam.xzbids" placeholder="请选择班级"></j-select-banji>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <edu-button type="5" @click="searchQuery" icon="search" title="搜索" style="margin-bottom: 0"></edu-button><edu-button type="7" @click="searchReset" icon="delete" title="清除" style="margin-bottom: 0"></edu-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <edu-button
        @click="batchAble"
        type="4"
        icon="check-circle"
        title="发布"
        ></edu-button>

      <edu-button
        @click="batchDisable"
        type="8"
        icon="close-circle"
        title="取消发布"
        ></edu-button>

      <edu-button  @click="generate" type="6" icon="plus" title="生成教学任务"></edu-button>
<!--      <a-button @click="reuse" type="primary" icon="plus">教学复用</a-button>-->
      <edu-button type="1" @click="searchQuery" icon="sync" title="刷新"></edu-button>
      <edu-button @click="oneButtonPublish" type="3" icon="plus" title="一键发布"></edu-button>
    <!--      @click="batchDel" -->
      <edu-button-delete type="7" ref="batchDelBtn" @del="batchDelAction" @click="batchDelConfirm" icon="delete" title="删除"></edu-button-delete>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('ve_jw_jxrw')">导出</a-button>-->
<!--      <a-upload-->
<!--        name="file"-->
<!--        :showUploadList="false"-->
<!--        :multiple="false"-->
<!--        :headers="tokenHeader"-->
<!--        :action="importExcelUrl"-->
<!--        @change="handleImportExcel"-->
<!--      >-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
<!--      <a-button @click="recycle" type="danger" icon="delete">回收站</a-button>-->
      <edu-button type="7" @click="recycle" icon="delete" title="回收站"></edu-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="showDataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ fixed: true, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无此图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt="图片不存在"
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无此文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
<!--          <a @click="handleEdit(record)">编辑</a>-->
          <edu-label-button type="3" @click="handleEdit(record)" title="编辑"></edu-label-button>
          <a-divider type="vertical" />
          <edu-delete-button @click="handleDelete(record.id)" type="4" title="删除"></edu-delete-button>
<!--          <a-dropdown>-->
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
<!--          </a-dropdown>-->
        </span>

        <span slot="ismerged" slot-scope="text, record">
          <a-switch
            default-checked
            @change="changeIsmerged(record.id, checked)"
            v-model="record.ismergedclass"
            :active-value="1"
            :inactive-value="0"
          />
        </span>

        <span slot="ispublish" slot-scope="text, record">
          <a-switch
            default-checked
            @change="changeIsPublish(record.id, checked)"
            v-model="record.ispublish"
            :active-value="1"
            :inactive-value="0"
          />
        </span>
      </a-table>
    </div>
    <jw-select-class ref="selectForm" @ok="modalFormOk"></jw-select-class>
    <veJwJxrw-modal ref="publishForm" @ok="searchQuery"></veJwJxrw-modal>
    <veJwJxrw-edit-modal ref="modalForm" @ok="searchQuery"></veJwJxrw-edit-modal>
    <ve-jw-jxrw-generate ref="generateForm" @ok="searchQuery"></ve-jw-jxrw-generate>
    <ve-jw-jxrw-filter ref="filter" @ok="filterFormOk"></ve-jw-jxrw-filter>
    <ve-jw-jxrw-reuse ref="reuse" @ok="searchQuery"></ve-jw-jxrw-reuse>
    <ve-jw-jxrw-recycle-bin ref="recycle" @ok="searchQuery"></ve-jw-jxrw-recycle-bin>
  </a-card>
</template>

<script>
  // import { EduListMixin } from '@/mixins/EduListMixin'
import { EduListMixin } from '@/mixins/KwglMixin'
import VeJwJxrwModal from './modules/VeJwJxrwModal'
import VeJwJxrwEditModal from './modules/VeJwJxrwEditModal'
import { postAction, getAction } from '../../api/manage'
import VeJwJxrwReuse from './modules/VeJwJxrwReuse'
import JwSelectClass from '@views/jxzy/modules/JwSelectClass'
import VeJwJxrwGenerate from './modules/VeJwJxrwGenerate'
import VeJwJxrwFilter from './modules/VeJwJxrwFilter.vue'
import VeJwJxrwRecycleBin from './modules/VeJwJxrwRecycleBin.vue'
  import JSelectBanji from '../../components/kwglbiz/JSelectBanji'

export default {
  name: 'VeJwJxrwList',
  mixins: [EduListMixin],
  components: {
    JSelectBanji,
    VeJwJxrwModal,
    VeJwJxrwEditModal,
    VeJwJxrwReuse,
    JwSelectClass,
    VeJwJxrwGenerate,
    VeJwJxrwFilter,
    VeJwJxrwRecycleBin,
  },
  data() {
    return {
      description: 've_jw_jxrw管理页面',
      disableMixinCreated: true,
      // 表头
      columns: [
        {
          title: '学期',
          align: 'center',
          dataIndex: 'semester',
        },

        {
          title: '课程性质',
          align: 'center',
          dataIndex: 'kcxz_dictText',
        },
        {
          title: '院系',
          align: 'center',
          dataIndex: 'falidName',
        },
        {
          title: '专业',
          align: 'center',
          dataIndex: 'specidName',
        },
        {
          title: '班级',
          align: 'center',
          dataIndex: 'classname',
        },

        {
          title: '课程',
          align: 'center',
          dataIndex: 'kcid_dictText',
        },
        {
          title: '教师',
          align: 'center',
          dataIndex: 'teacheruseridName',
        },
        {
          title: '教室',
          align: 'center',
          dataIndex: 'jsid_dictText',
        },

        {
          title: '合班',
          align: 'center',
          dataIndex: 'ismergedclass',
          scopedSlots: { customRender: 'ismerged' },
        },

        {
          title: '状态',
          align: 'center',
          dataIndex: 'checkstatus_dictText',
        },
        {
          title: '发布',
          align: 'center',
          dataIndex: 'ispublish',
          scopedSlots: { customRender: 'ispublish' },
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/jxrw/veJwJxrw/list',
        delete: '/jxrw/veJwJxrw/delete',
        deleteBatch: '/jxrw/veJwJxrw/deleteBatch',
        exportXlsUrl: '/jxrw/veJwJxrw/exportXls',
        importExcelUrl: 'jxrw/veJwJxrw/importExcel',
        updateIsmerged: '/jxrw/veJwJxrw/updateIsmerged',
        updatePublishBatch: '/jxrw/veJwJxrw/changePublishByIds',
        changeIsPublish: '/jxrw/veJwJxrw/changeIsPublish',
      },
      dictOptions: {},
      isorter: [],
    }
  },
  created() {
    this.queryParam.delflag = '0'
    this.loadData()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},

    //查询班级
    onSearchClass() {
      this.$refs.selectForm.show()
    },

    //接受回送班级信息
    modalFormOk(row, id) {
      console.log('当前选中班级id', id)
      //this.jcid=id

      this.queryParam.jxbid = id
      this.$refs.class.value = row.name
    },
    //接受所选教室信息
    filterFormOk(teacheruserid, jsid, year, semid, falid, specid, jxbid, kcid,xzbids) {
      //this.jcid=id
      if (teacheruserid != null) {
        this.queryParam.teacheruserid = teacheruserid
        console.log('当前选中教师id', teacheruserid)
      }
      if (xzbids != null) {
        this.queryParam.xzbids = xzbids
        console.log('当前选中班级id', xzbids)
      }
      if (jsid != null) {
        this.queryParam.jsid = jsid
        console.log('当前选中教室id', jsid)
      }
      if (year != null) {
        this.queryParam.year = year
        console.log('当前选中学年id', year)
      }
      if (semid != null) {
        this.queryParam.semid = semid
        console.log('当前选中教师id', teacheruserid)
      }
      if (falid != null) {
        this.queryParam.falid = falid
        console.log('当前选中学院id', falid)
      }
      if (specid != null) {
        this.queryParam.specid = specid
        console.log('当前选中教师id', teacheruserid)
      }
      if (jxbid != null) {
        this.queryParam.jxbid = jxbid
        console.log('当前选中教学班id', jxbid)
      }
      if (kcid != null) {
        this.queryParam.kcid = kcid
        console.log('当前选中课程id', kcid)
      }
      this.loadData()
    },

    //教学复用
    reuse: function () {
      this.$refs.reuse.edit()
      this.$refs.reuse.title = '教学复用'
      this.$refs.reuse.disableSubmit = false
    },

    //筛选
    filter: function () {
      this.$refs.filter.edit()
      this.$refs.filter.title = '筛选'
      this.$refs.filter.disableSubmit = false
    },

    //更新是否合班状态
    changeIsmerged(id, checked) {
      this.loading = true
      postAction(this.url.updateIsmerged, { id: id })
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData()
            this.onClearSelected()
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },

    //更新发布状态
    changeIsPublish(id, checked) {
      this.loading = true
      getAction(this.url.changeIsPublish, { id: id })
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData()
          } else {
            this.$message.warning(res.message)
            this.loadData()
          }
        })
        .finally(() => {
          this.loading = false
        })
    },

    //生成教学任务
    generate: function () {
      this.$refs.generateForm.edit()
      this.$refs.generateForm.title = '生成教学任务'
      this.$refs.generateForm.disableSubmit = false
    },

    //一键发布
    oneButtonPublish: function () {
      this.$refs.publishForm.edit()
      this.$refs.publishForm.title = '一键发布'
      this.$refs.publishForm.disableSubmit = false
    },

    //回收站
    recycle: function () {
      this.$refs.recycle.show()
      this.$refs.recycle.title = '回收站'
      this.$refs.recycle.disableSubmit = false
    },

    //批量取消发布
    batchDisable: function () {
      if (!this.url.updatePublishBatch) {
        this.$message.error('请设置url.updatePublishBatch!')
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        var that = this
        this.$confirm({
          title: '确认取消发布',
          content: '是否取消发布选中数据?',
          onOk: function () {
            that.loading = true
            getAction(that.url.updatePublishBatch, { ids: ids, status: 0 })
              .then((res) => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.loadData()
                  that.onClearSelected()
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.loading = false
              })
          },
        })
      }
    },
    //批量发布
    batchAble: function () {
      if (!this.url.updatePublishBatch) {
        this.$message.error('请设置url.updatePublishBatch!')
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        var that = this
        this.$confirm({
          title: '确认发布',
          content: '是否发布选中数据?',
          onOk: function () {
            that.loading = true
            getAction(that.url.updatePublishBatch, { ids: ids, status: 1 })
              .then((res) => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.loadData()
                  that.onClearSelected()
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.loading = false
              })
          },
        })
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>